$(document).ready(function() {

    if($(document).height()<540){
    $('#describe').attr('rows', 4);
   }
 if($(document).height()<490){
   $(".btndiv").css('bottom', '10%');
   
    $('h1').css('padding-top', '1%');
    $(".arrow-up").css('bottom', '5%');
     $(".swiper-slide-2-body").css('top', '-5%');
    $('.iptop').addClass('divip10');
      $('.ipbottom').addClass('divip15');
    
  }
   var js = 0.00;
  var dh ; 
  function sj(){
          js=js+0.01;
          $('.swiper-slide-4-span1').text(js.toFixed(2)+'秒');
        }
  var mySwiper = new Swiper('.swiper-container', {
    direction: 'vertical',
    longSwipesRatio : 0.1,
    mousewheelControl: true,
    preloadImages: true,
    updateOnImagesReady: true,
    allowSwipeToPrev : false,
    nextButton: '.arrow-up',
    preventLinksPropagation : false,
    loop: false,
    onImagesReady: function(swiper) {
      $("#loading").hide();
    },
    onInit: function(swiper) {
      swiperAnimateCache(swiper);
      swiperAnimate(swiper);
    },
    onSlideChangeEnd: function(swiper) {
      swiperAnimate(swiper);
   if(swiper.activeIndex == 3) {
       mySwiper.disableMousewheelControl();
       }
      
    },
     onSlideChangeStart: function(swiper){
      
          if (swiper.activeIndex == 0) {
          
       } else if(swiper.activeIndex == 3) {
     mySwiper.detachEvents();
     dh = setInterval(sj,10);
       } }
  });
/*    $(".btndiv").click(function(){
  mySwiper.slideTo(4, 1000, true);
  });
*/

  $("#wxTips").tap(function() {
    $("#wxTips").hide();
  });
  $("#audio_btn").click(function() {
    if ($("#audio_btn").hasClass('off')) {
      $("#audio_btn").removeClass('off');
      $("#yinfu").addClass("rotate");
      $("#media").get(0).play();
    } else {
      $("#audio_btn").addClass('off');
      $("#yinfu").removeClass("rotate");
      $("#media").get(0).pause();
    }
  });

$("#mask_index").wScratchPad({
      size        : 40,
      bg          : "Public/img/bj3.jpg",
      fg          : "Public/img/canvas.png",
      realtime    : false,
      scratchFunc : function(e, percent){
    
         
      },
      scratchDown :function(e, percent){

        
         /* dh = setInterval(sj(),1000);*/
      },
      scratchUp   : function(e, percent){
           
         
          if(percent > 40){
            mySwiper.attachEvents();
           clearInterval(dh);
               /*js*/         /*此处js变量为秒数*/
              this.clear();
              this.enable("enabled", false);
              $("#mask_index").hide(300);

              //提交给服务端
              var play_time = $(".swiper-slide-4-span1").text();
              play_time = play_time.replace("秒", '');

              param={play_time:play_time};

              $.post(reurl,param, function(data, textStatus, xhr) {
                  if(data.error === 0){
                      //提交成功
                      //alert('哎呦，涂完了.共花了'+ $(".swiper-slide-4-span1").text());

                      //获取最新排名
                      $.post(rank_url,param, function(rank_data, textStatus, xhr) {
                        if(rank_data.error == 0){
                            //填充击败百分点
                            $("#percent").text(rank_data.percent);

                            //清空排名
                            var ran_list = $("#rank_list");
                            ran_list.empty();

                            //重新排名
                            var rows = rank_data.rows;
                            var len = rows.length;
                            for(var i=1;i<=len;i++){
                                ran_list.append(
                                  '<tr>'+
                                    '<td>'+i+'</td>'+
                                    '<td>'+rows[i-1]['nickname']+'</td>'+
                                    '<td>'+rows[i-1]['play_times']+'</td>'+
                                  '</tr>'
                                );

                            }
                        }
                      },'json');
                  }else{
                      alert(data.msg);
                  }
              },"json");
              //alert('哎呦，涂完了.共花了'+ $(".swiper-slide-4-span1").text());

          }
      },
      scratchMove : function(e, percent){

          
      },
      cursor: "crosshair"
});
});

